// 
function check_all(f)
{
    var chk = document.getElementsByName("chk[]");
	var chkall = document.getElementsByName("chkall");

    for (i=0; i<chk.length; i++)
        chk[i].checked = chkall.chkall.checked;
}

// 
// Trim
function Trim(obj1)
{
	obj1 = obj1.replace(/^(\s+)|(\s+)$/g, "")
	return obj1;
}

//
function validRadioAlert(arrVal, msgStr)
{
    var chk = document.getElementsByName(arrVal);
	var bchk = false;

	for (i=0; i<chk.length; i++)
	{
		if (chk[i].checked)
			bchk = true;
	}

	if (!bchk) 
	{
		alert(msgStr +" 하나 이상 선택하세요.");
		return false;
	}
	return true;
}

// 
// Input, select String null checking
function validFieldAlert(objInput, msgStr)
{
	if(objInput.value == "") 
	{
		if (msgStr)
		{
			alert(msgStr +" 입력해주세요");
			objInput.focus();	
		}
		return false;
	}

	return true;
}

//
function validSelectAlert(objInput, msgStr)
{
	if(objInput.value == "") 
	{
		if (msgStr)
		{
			alert(msgStr +" 선택해주세요");
			objInput.focus();	
		}
		return false;
	}

	return true;
}

// 
// 링크 점선 테두리 한번에 없애기 //document.onfocusin = bluring;
function bluring()
{
	if (event.srcElement.tagName == "a" || event.srcElement.tagName == "img")	document.body.focus();
}

// 
// 숫자 제거
function SetNum(obj)
{
	val=obj.value;
	re=/[^0-9]/gi;
	obj.value=val.replace(re,"");
}

//
// 포맷 체크
function isValidFormat(input, format) 
{
    if (input.value.search(format) != -1) 
	{
        return true;
    }
    return false;
}

//
//숫자입력 체크(onblur)
function isValidNumber(theForm, firstNum) 
{
	if(Trim(theForm.value) != "") 
	{
		theForm.value=Trim(theForm.value);

		var str=theForm.value;
		for (var i = 0; i< str.length; i++) 
		{
			var ch = str.substring(i, i + 1);
			if ( ( i==0 && ch=="-") || ch == ",") {}
			else
			{
				if ( (ch<"0" || ch>"9") ) 
				{
					alert(firstNum+" 숫자만 입력해주세요.");
					theForm.readonly = false;
					theForm.value = "";
					theForm.focus();
					return false;
				}
			}
		}
	}

	return true;
}

function onlyNumber() {

    if((event.keyCode<48)||(event.keyCode>57)) 
    {
      event.returnValue=false;
    }
}

//
//날짜 형식 체크
function isValidDate(o)
{	
	if (Trim(o.value) != ""){
		if(o.value.indexOf("-") +""=="-1")
		{
			alert("잘못된 형식입니다.")
			o.focus();
			return false;
		}
	}
	return true;
}

//
//이메일 형식 체크
function isValidMail(o)
{
	if (Trim(o.value) != ""){
		if(o.value.indexOf("@") +""=="-1" || o.value.indexOf(".") +""=="-1")
		{
			alert("잘못된 이메일 형식입니다.")
			o.focus();
			return false;
		}
	}
	return true;
}

//
// 이메일 형식 체크
function isValidMail2(strEmail)
{
	var format = /^((\w|[\-\.])+)\.([A-Za-z]+)$/;
    	return isValidFormat(strEmail, format);
}

//
// 이메일형식 체크2
function isValidMail3(str) 
{
	emailEx1 = /[^@]+@[A-Za-z0-9_\-]+\.[A-Za-z]+/;
	emailEx2 = /[^@]+@[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+\.[A-Za-z]+/;
	emailEx3 = /[^@]+@[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+\.[A-Za-z]+/;
	if(emailEx1.test(str)){ return true; };
	if(emailEx2.test(str)){ return true; };
	if(emailEx3.test(str)){ return true; };
	return false;
}

//
// 글자수 바이트로 제한
function ChkByte(objname,maxlength) 
{
	var objstr = objname.value; // 입력된 문자열을 담을 변수
	var objstrlen = objstr.length; // 전체길이

	// 변수초기화
	var maxlen = parseInt(maxlength,10); // 제한할 글자수 최대크기
	var i = 0; // for문에 사용
	var bytesize = 0; // 바이트크기
	var strlen = 0; // 입력된 문자열의 크기
	var onechar = ""; // char단위로 추출시 필요한 변수
	var objstr2 = ""; // 허용된 글자수까지만 포함한 최종문자열

	// 입력된 문자열의 총바이트수 구하기
	for(i=0; i< objstrlen; i++) 
	{
		// 한글자추출
		onechar = objstr.charAt(i);

		if (escape(onechar).length > 4) 
		{
			bytesize += 2;			// 한글이면 2를 더한다.
		} 
		else 
		{
			bytesize++;				// 그밗의 경우는 1을 더한다.
		}

		if(bytesize <= maxlen)		// 전체 크기가 maxlen를 넘지않으면
		{   
			strlen = i + 1;			// 1씩 증가
		}
	}

	// 총바이트수가 허용된 문자열의 최대값을 초과하면
	if (bytesize > maxlen)
	{
		objstr2 = objstr.substr(0, strlen);
		objname.value = '';
		return true;
	}
	return false;
}

//
// 모두 선택 해제
var checkAllFlag = true;

function CheckAll(A,B,C)	// CheckAll(폼이름, 개체이름, true/false)
{
	var X=eval("document.forms."+A+"."+B)
	for (c=0;c<X.length;c++)
		X[c].checked=checkAllFlag;

	checkAllFlag = !checkAllFlag;
}

//
// 기본창 띄우기
function WindowOpen(Url, popName, popwidth, popheight)
{
	var height = screen.height;
	var width = screen.width;
	var left = 0;
	var top = 0;
	popheight = popheight + 27;
	window.open(Url, popName, "width="+popwidth+",height="+popheight+",scrollbars=no,toolbar=no,left="+left+",top="+top+"")
}

// 센터 창 띄우기(scrollbars no)
function WindowOpenCenter(Url, popName, popwidth, popheight)
{
	var LeftPosition = (screen.width) ? (screen.width-popwidth)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-popheight)/2 : 0;
	var settings = 'height='+popheight+',width='+popwidth+',top='+TopPosition+',left='+LeftPosition+',status=no,toolbar=no,menubar=no,location=no,fullscreen=no,resizable=no,scrollbars=no';
	win = window.open(Url,popName,settings)
}

// 센터 창 띄우기(scrollbars yes)
function WindowOpenCenter2(Url, popName, popwidth, popheight)
{
	var LeftPosition = (screen.width) ? (screen.width-popwidth)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-popheight)/2 : 0;
	var settings = 'height='+popheight+',width='+popwidth+',top='+TopPosition+',left='+LeftPosition+',status=no,toolbar=no,menubar=no,location=no,fullscreen=no,resizable=no,scrollbars=yes';
	win = window.open(Url,popName,settings)
}

// E7.0 브라우져 창 높이 조절
function WindowOpenNomargin(Url, popName, popwidth, popheight)
{
	var height = screen.height;
	var width = screen.width;
	popheight = popheight + 27;
	window.open(Url, popName, "width="+popwidth+",height="+popheight+",scrollbars=no,toolbar=no,left=0,top=0")
}

// 주민등록번호 체크
function jumin_check(o, registNum1, registNum2 )
{
	var chk =0;
	var yy = registNum1.value.substring(0,2);
	var mm = registNum1.value.substring(2,4);
	var dd = registNum1.value.substring(4,6);
	var sex = registNum2.value.substring(0,1);


	if((registNum1.value.length!=6) || (yy <25||mm <1||mm>12||dd<1))
	{
		o.msg.value = "주민등록번호를 바로 입력하여 주십시오.";
		registNum1.value="";
		registNum2.value="";
		registNum1.focus();
		return true;
	}

	if((sex != 1 && sex !=2 && sex != 3 && sex != 4) || (registNum2.value.length!= 7))
	{
		o.msg.value = "주민등록번호를 바로 입력하여 주십시오.";
		registNum1.value="";
		registNum2.value="";
		registNum1.focus();
		return true;
	}

	for (var i = 0; i <=5 ; i++)
	{
		chk = chk + ((i%8+2) * parseInt(eval(registNum1.value.substring(i,(i+1)))));
	}
	for (var i = 6; i <=11 ; i++)
	{
		chk = chk + ((i%8+2) * parseInt(eval(registNum2.value.substring((i-6),(i-5)))));
	}

	chk = 11 - (chk %11);
	chk = chk % 10;

	if (chk != registNum2.value.substring(6,7))	
	{
		o.msg.value = "유효하지 않는 주민등록번호입니다.\n\n타인의 주민등록번호를 도용하거나 허위 기제할 경우 회원가입이 취소됩니다.";
		registNum1.value="";
		registNum2.value="";
		registNum1.focus();
		return true;
	}
}


// object type 확인
function isObject(a) 
{
    return (a && typeof a == 'object');
}

// display설정 변경
function changeTb(tbName, tbCount, tbNum) 
{
	var a;
	for(i=1;i<=tbCount;i++)
	{
		a = eval("document.all."+tbName+i);

		if(i != tbNum) 
		{
			a.style.display = 'none';
		}
		else 
		{
			a.style.display = 'block';
		}
	}
}

// 아이프레임 자동 길이 조절 스크립트
function resizeFrame(iframeObj)
{
	var innerBody = iframeObj.contentWindow.document.body;
	oldEvent = innerBody.onclick;
	innerBody.onclick = function(){ resizeFrame(iframeObj, 1);oldEvent; };
	var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight) + 5;
	iframeObj.style.height = innerHeight;
	var innerWidth = innerBody.scrollWidth + (innerBody.offsetWidth - innerBody.clientWidth);
	iframeObj.style.width = innerWidth;
	if( !arguments[1] )        /* 특정 이벤트로 인한 호출시 스크롤을 그냥 둔다. */
		this.scrollTo(1,1);
}

// image
function clrImg(obj)
{
    obj.style.backgroundImage="";
	obj.onkeydown=obj.onmousedown=null;
}

// 영문검사
function isEng(str)
{
	for(var i=0; i < str.length; i++)
	{
		achar = str.charCodeAt(i);
		if(achar > 255)
		{
			return false;
		}
	}

	return true;
}

// Alphabet 필드
function IsAlphabet(str)
{
	var vStr = str.toUpperCase();
	for(var i = 0; i < vStr.length; i++)
	{
		if(vStr.charAt(i) < 'A' || vStr.charAt(i) > 'Z')
		{
			return false;
		}
	}
	return true;
}

// Alphabet + Number 필드
function IsAlphaDigit(obj, str)
{
	var strTemp = obj.value.toUpperCase();
	for(var i = 0; i < strTemp.length; i++)
	{
		if(strTemp.charAt(i) < '0' || (strTemp.charAt(i) > '9' && strTemp.charAt(i) < 'A') ||  strTemp.charAt(i) > 'Z') 
		{
		    alert( str + " 입력해 주세요." );
			obj.value = "";
			obj.focus();
			return false;
		}
	}
	return true;
}

// Number 필드
function comFuncIsDigit(obj, str)
{
	for (i=0; i < obj.value.length; i++)
	{
		if (obj.value.charAt(i) < '0' || obj.value.charAt(i) > '9')
		{
			alert( str + " 숫자만 입력해 주세요." );
			obj.value = "";
			obj.focus();
			return false;
		}
	}
	return true;
}

// Number 검사
function onlyNum(obj) {
		var num = obj.value;
		num = Trim(num).replace(/[^0-9]/g,"");
		obj.value = num;
		return;
}

// 필드 Length
function CheckLength(obj, min, max, str)
{
	var iLength = obj.value.length;
	if(iLength < min || iLength > max) 
	{
		alert(str + " " + min + "자 이상 " + max + "자 이내로 입력해 주세요.");
		obj.focus();
		return false;
	}
	else return true;
}

// 필드 Length
function CheckLength1(obj, strNum, str)
{
	var iLength = obj.value.length;
	if(iLength < strNum || iLength > strNum) 
	{
		alert( str + " " + strNum + "자로 입력해 주세요." );
		obj.focus();
		return false;
	}
	else return true;
}

// 트랙백 복사하기
function SelectCopy(s)
{
    var doc = document.body.createTextRange();
    doc.moveToElementText(document.all(s));
    doc.select();
    doc.execCommand('copy');
    alert('주소가 복사되었습니다.\n\n주소창에 Ctrl + V 를 눌러주세요.');
}

// 레이어 처리 스크립트
var previd = null;

function displaysub(subid) 
{
	if (previd != null) 
	{
		if (previd != subid) 
		{
			previd.style.display = "none";
		}
	}

	if (subid.style.display == "none") 
	{
		subid.style.display = "block";
	} 
	else 
	{
		subid.style.display = "none";
	}
	previd = subid;
}
 
//ID 찾기 
function idcheck(obj)
{
	var comp = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
	var str = Trim(obj.value);
	var len = str.length;

	if (len > 0) {
		for(i=0;i<len;i++) {
			if (comp.indexOf(str.substring(i,i+1))<0) {
				alert("허용된 문자가 아닙니다. 다시 입력해 주십시오");
				obj.focus();
				return false;
			}
		}

		if (len <4) {
			alert("아이디는 4자이상입니다.");
			obj.focus();
			return false;
		} else if (len > 12) {
			alert("아이디는 12자이하입니다.");
			obj.focus();
			return false;
		}
	}

	if(str == ""){
		alert("먼저 아이디를 입력해주세요.");
		obj.focus();
		return false;
	}

	return true;
}

function fnLpad(n,s,c){
	var n_c = n.length;
	for(i=0;i<c-n_c;i++){
		var p = p + c;
	}
	return p + n;
}

function strtotime (str, now) {
    // Convert string representation of date and time to a timestamp  
    // 
    // version: 1107.2516
    // discuss at: http://phpjs.org/functions/strtotime    // +   original by: Caio Ariede (http://caioariede.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: David
    // +   improved by: Caio Ariede (http://caioariede.com)
    // +   improved by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Wagner B. Soares
    // +   bugfixed by: Artur Tchernychev
    // %        note 1: Examples all have a fixed timestamp to prevent tests to fail because of variable time(zones)
    // *     example 1: strtotime('+1 day', 1129633200);
    // *     returns 1: 1129719600    // *     example 2: strtotime('+1 week 2 days 4 hours 2 seconds', 1129633200);
    // *     returns 2: 1130425202
    // *     example 3: strtotime('last month', 1129633200);
    // *     returns 3: 1127041200
    // *     example 4: strtotime('2009-05-04 08:30:00');    // *     returns 4: 1241418600
    var i, match, s, strTmp = '',
        parse = '';
 
    strTmp = str;    strTmp = strTmp.replace(/\s{2,}|^\s|\s$/g, ' '); // unecessary spaces
    strTmp = strTmp.replace(/[\t\r\n]/g, ''); // unecessary chars
    if (strTmp == 'now') {
        return (new Date()).getTime() / 1000; // Return seconds, not milli-seconds
    } else if (!isNaN(parse = Date.parse(strTmp))) {        return (parse / 1000);
    } else if (now) {
        now = new Date(now * 1000); // Accept PHP-style seconds
    } else {
        now = new Date();    }
 
    strTmp = strTmp.toLowerCase();
 
    var __is = {        day: {
            'sun': 0,
            'mon': 1,
            'tue': 2,
            'wed': 3,            'thu': 4,
            'fri': 5,
            'sat': 6
        },
        mon: {            'jan': 0,
            'feb': 1,
            'mar': 2,
            'apr': 3,
            'may': 4,            'jun': 5,
            'jul': 6,
            'aug': 7,
            'sep': 8,
            'oct': 9,            'nov': 10,
            'dec': 11
        }
    };
     var process = function (m) {
        var ago = (m[2] && m[2] == 'ago');
        var num = (num = m[0] == 'last' ? -1 : 1) * (ago ? -1 : 1);
 
        switch (m[0]) {        case 'last':
        case 'next':
            switch (m[1].substring(0, 3)) {
            case 'yea':
                now.setFullYear(now.getFullYear() + num);                break;
            case 'mon':
                now.setMonth(now.getMonth() + num);
                break;
            case 'wee':                now.setDate(now.getDate() + (num * 7));
                break;
            case 'day':
                now.setDate(now.getDate() + num);
                break;            case 'hou':
                now.setHours(now.getHours() + num);
                break;
            case 'min':
                now.setMinutes(now.getMinutes() + num);                break;
            case 'sec':
                now.setSeconds(now.getSeconds() + num);
                break;
            default:                var day;
                if (typeof(day = __is.day[m[1].substring(0, 3)]) != 'undefined') {
                    var diff = day - now.getDay();
                    if (diff == 0) {
                        diff = 7 * num;                    } else if (diff > 0) {
                        if (m[0] == 'last') {
                            diff -= 7;
                        }
                    } else {                        if (m[0] == 'next') {
                            diff += 7;
                        }
                    }
                    now.setDate(now.getDate() + diff);                }
            }
            break;
 
        default:            if (/\d+/.test(m[0])) {
                num *= parseInt(m[0], 10);
 
                switch (m[1].substring(0, 3)) {
                case 'yea':                    now.setFullYear(now.getFullYear() + num);
                    break;
                case 'mon':
                    now.setMonth(now.getMonth() + num);
                    break;                case 'wee':
                    now.setDate(now.getDate() + (num * 7));
                    break;
                case 'day':
                    now.setDate(now.getDate() + num);                    break;
                case 'hou':
                    now.setHours(now.getHours() + num);
                    break;
                case 'min':                    now.setMinutes(now.getMinutes() + num);
                    break;
                case 'sec':
                    now.setSeconds(now.getSeconds() + num);
                    break;                }
            } else {
                return false;
            }
            break;        }
        return true;
    };
 
    match = strTmp.match(/^(\d{2,4}-\d{2}-\d{2})(?:\s(\d{1,2}:\d{2}(:\d{2})?)?(?:\.(\d+))?)?$/);    if (match != null) {
        if (!match[2]) {
            match[2] = '00:00:00';
        } else if (!match[3]) {
            match[2] += ':00';        }
 
        s = match[1].split(/-/g);
 
        for (i in __is.mon) {            if (__is.mon[i] == s[1] - 1) {
                s[1] = i;
            }
        }
        s[0] = parseInt(s[0], 10); 
        s[0] = (s[0] >= 0 && s[0] <= 69) ? '20' + (s[0] < 10 ? '0' + s[0] : s[0] + '') : (s[0] >= 70 && s[0] <= 99) ? '19' + s[0] : s[0] + '';
        return parseInt(this.strtotime(s[2] + ' ' + s[1] + ' ' + s[0] + ' ' + match[2]) + (match[4] ? match[4] / 1000 : ''), 10);
    }
     var regex = '([+-]?\\d+\\s' + '(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?' + '|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday' + '|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday)' + '|(last|next)\\s' + '(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?' + '|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday' + '|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday))' + '(\\sago)?';
 
    match = strTmp.match(new RegExp(regex, 'gi')); // Brett: seems should be case insensitive per docs, so added 'i'
    if (match == null) {
        return false;    }
 
    for (i = 0; i < match.length; i++) {
        if (!process(match[i].split(' '))) {
            return false;        }
    }
 
    return (now.getTime() / 1000);
}


//////////////////////////////////////////
// 댓글 관련 start
//////////////////////////////////////////
	// 댓글 저장
	function cmt_insert(seq) {
		if(jQuery('#cmt_contents').val() == "") {
			alert("insert comment!");
			return;
		}

		try{
			$.ajax({
				type: "POST",
				url: "cmt_proc.php",
				data: "seq="+ seq +"&cmt_mode=w&cmt_contents="+ encodeURIComponent(jQuery('#cmt_contents').val()),
				success: function(msg){
					if(msg == "s"){
						jQuery('#cmt_contents').val("");
						cmt_list(seq);
					}else{
						alert(msg);
					}
				}
			});
		}catch(e){}
	}

	// 댓글 삭제
	function cmt_delete(seq,cmt_seq){
		//if(!confirm("삭제하시겠습니까?")) return;
		try{
			$.ajax({
				type: "POST",
				url: "cmt_proc.php",
				data: "cmt_seq="+ cmt_seq +"&cmt_mode=d",
				success: function(msg){
					if(msg == "s"){
						$('#cmt_'+ cmt_seq).html("삭제처리중");
						cmt_list(seq);
					}else{
						alert(msg);
					}
				}
			});
		}catch(e){}
	}

	// 댓글 목록
	function cmt_list(seq){
		$.getJSON('cmt_proc.php?seq='+ seq, function (data){
		  if (data.length > 0) {
			var temp ='';//<div style="padding: 8px 0px 0px 15px"></div>';
			for(var i =0; i < data.length; i++){
				temp =='<div style="margin:10px 0 7 0;" id="cmt_'+ data[i]['seq'] +'">';
				temp +='<table width="720" border="0" cellspacing="0" cellpadding="0" align="center">';
				temp +='	<tr>';
				temp +='		<td height="1"  bgcolor="DDDDDD" colspan="2"></td>';
				temp +='	</tr>';
				temp +='	<tr height="30">';
				temp +='		<td width="50%" bgcolor="FDFDFD" class="fs12_b_4 lpad10"><img src="../img/arr01.gif" align="absmiddle"><B>'+ data[i]['mb_name'] +'</B>&nbsp;&nbsp;&nbsp;';

				if(data[i]['chk'] == 's'){
				temp +='<a href="javascript:cmt_delete('+seq+','+ data[i]['seq'] +');"><img src="../img/bbs/btn_comment_del01.gif" align="absmiddle"></a>';
				}
				temp +='</td>';
				temp +='		<td width="50%" bgcolor="FDFDFD" class="fs11_5 rpad10" align="right">2011-07-12 10:07:36</td>';
				temp +='	</tr>';
				temp +='	<tr>';
				temp +='		<td height="1"  background="../img/dot01.gif" colspan="2"></td>';
				temp +='	</tr>';
				temp +='	<tr>';
				temp +='		<td colspan="2" style="padding:15px;">'+ data[i]['cmt_contents'] +'</a></td>';
				temp +='	</tr>';
				temp +='</table>';
				temp +='</div>';
			}			
		  }else{
				temp =='<div style="margin:10px 0 7 0;">&nbsp;</div>';
		  }
		  $('#cmt_list').empty().html(temp);
		});
	}
//////////////////////////////////////////
// 댓글 관련 end
//////////////////////////////////////////

	function file_down(fseq){
		var f = document.form1;
		f.fmode.value = "down";
		f.fseq.value = fseq;
		f.method = "post";
		f.action = "../inc/down.php";
		f.submit();
	}


	function resizeBoardImage(imageWidth, borderColor) {

		var content = document.getElementById("bbsContent");
		if (content) {
			var target = content.getElementsByTagName("img");
			if (target) {
				var imageHeight = 0;

				for(i=0; i<target.length; i++) { 
					// 원래 사이즈를 저장해 놓는다
					target[i].tmpWidth  = target[i].width;
					target[i].tmpHeight = target[i].height;

					//alert(target[i].width);

					// 이미지 폭이 테이블 폭보다 크다면 테이블폭에 맞춘다
					if(target[i].width > imageWidth) {
						imageHeight = parseFloat(target[i].width / target[i].height)
						target[i].width = imageWidth;
						target[i].height = parseInt(imageWidth / imageHeight);

						// 스타일에 적용된 이미지의 폭과 높이를 삭제한다
						target[i].style.width = '';
						target[i].style.height = '';
					}

					if (borderColor) {
						target[i].style.borderWidth = '1px';
						target[i].style.borderStyle = 'solid';
						target[i].style.borderColor = borderColor;
					}
				}
			}
		}
	}

// 천단위 콤마적용 (number_format()
	function formatnumber(v1,v2){
		var str = new Array(); 
		v1 = String(v1); 
		for(var i=1;i<=v1.length;i++){ 
			if(i % v2) str[v1.length-i] = v1.charAt(v1.length-i); 
			else str[v1.length-i] = ','+v1.charAt(v1.length-i); 
		}
		return str.join('').replace(/^,/,''); 
	}

	function urldecode(str) {
		// Decodes URL-encoded string  
		// 
		// version: 1109.2015
		// discuss at: http://phpjs.org/functions/urldecode
		// +   original by: Philip Peterson
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +      input by: AJ
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   improved by: Brett Zamir (http://brett-zamir.me)
		// +      input by: travc
		// +      input by: Brett Zamir (http://brett-zamir.me)
		// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   improved by: Lars Fischer
		// +      input by: Ratheous
		// +   improved by: Orlando
		// +      reimplemented by: Brett Zamir (http://brett-zamir.me)
		// +      bugfixed by: Rob
		// +      input by: e-mike
		// +   improved by: Brett Zamir (http://brett-zamir.me)
		// %        note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
		// %        note 2: Please be aware that this function expects to decode from UTF-8 encoded strings, as found on
		// %        note 2: pages served as UTF-8
		// *     example 1: urldecode('Kevin+van+Zonneveld%21');
		// *     returns 1: 'Kevin van Zonneveld!'
		// *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
		// *     returns 2: 'http://kevin.vanzonneveld.net/'
		// *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
		// *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
		return decodeURIComponent((str + '').replace(/\+/g, '%20'));
	}

	 //콤마찍기
	function numberFormat(num) {
/*
		if(num == undefined) {
			 return 0;
		}else{
			  num = unNumberFormat(num);
			  var pattern = /(-?[0-9]+)([0-9]{3})/;
			  while(pattern.test(num)) {
			  num = num.replace(pattern,"$1,$2");
			  }
			  return num;
		}
*/
	 return num;
	}
	 
	//콤마제거
	function unNumberFormat(num) {
/*
		if(num > 0){
			return (num.replace(/\,/g,""));
		}
*/
	}

	// 아래 함수는 업그레이드 판 (소수점 정상 인식, 음수 정상 인식)
	function number_format(data){
		var prev_data="";
		if(Number(data)<0){
			prev_data="-";
			data=String(data).replace("-","");
		}

		var num_str=String(data);
		var tmp = '';
		var number = new Array;
		var cutlen = 3;
		var comma = ',';
		var nnn;
		var aaa;
		var number_format_str="";
		var data_ary=new Array();
		data_ary=num_str.split(".");

		for(aaa=0; aaa<data_ary.length; aaa++){
			if(!number[aaa]) number[aaa]="";
				var str=String(data_ary[aaa]);
				var len = str.length;
				var mod = (len % cutlen);
				var kkk = cutlen - mod;

				for (nnn=0; nnn<str.length; nnn++){
					number[aaa] = number[aaa] + str.charAt(nnn);
					if (nnn < str.length - 1){
						kkk++;
						if ((kkk % cutlen) == 0){
							number[aaa] = number[aaa] + comma;
							kkk = 0;
						}
					}
				}
				
				if(aaa>0) {
					number_format_str+="."+number[aaa];
				}else{
					number_format_str+=number[aaa];
				}
		}
		return prev_data+number_format_str;
	}

	// a 태그에서 onclick 이벤트를 사용하지 않기 위해
	function win_open(url, name, option)
	{
		var popup = window.open(url, name, option);
		popup.focus();
	}

	// 우편번호 창
	function win_zip(frm_name, frm_zip1, frm_zip2, frm_addr1, frm_addr2)
	{
		url = "/lib/zip.php?frm_name="+frm_name+"&frm_zip1="+frm_zip1+"&frm_zip2="+frm_zip2+"&frm_addr1="+frm_addr1+"&frm_addr2="+frm_addr2;
		win_open(url, "winZip", "left=50,top=50,width=550,height=480,scrollbars=1");
	}

	function fn_mn_period(form_dt, to_dt) {
		var f = document.searForm;
		f.fdt.value = form_dt;
		f.tdt.value = to_dt;
	}